package zero.tech.games.mj.event;

import com.alibaba.fastjson.JSONObject;

import zero.tech.core.ZeroContext;
import zero.tech.core.data.SimpleUser;
import zero.tech.core.event.EventCallbackListener;
import zero.tech.core.event.EventType;
import zero.tech.games.common.ClubMemberUtil;
import zero.tech.games.entity.games.Club;
import zero.tech.games.entity.games.ClubMember;
import zero.tech.games.logic.data.LogicEventType;
import zero.tech.games.mj.data.MjConfig;

/**
 * 检测创建俱乐部房间需要的钱
 * @author ludry
 *
 */
public class CheckCreateClubRoomMoney implements EventCallbackListener<Boolean>{

	@Override
	public EventType netEventType() {
		return LogicEventType.CHECK_CREATE_CLUB_ROOM_NEEDMONEY;
	}

	@Override
	public Boolean notifyEvent(Object... objs) {
		SimpleUser simpleUser=(SimpleUser) objs[0];
		String configStr=(String) objs[1];
		Club club=(Club) objs[2];
		MjConfig mjConfig = JSONObject.parseObject(configStr, MjConfig.class);
		Long admission_fee=mjConfig.getAdmission_fee();
		ClubMemberUtil clubMemberUtil=ZeroContext.getInstance(ClubMemberUtil.class);
		int uid=simpleUser.getUid();
		int club_id=club.getClub_id();
		ClubMember clubMember=clubMemberUtil.getClubMember(club_id,uid);
		long tea=clubMember.getTea();
		if(tea<admission_fee) {
			return false;
		}
		return true;
	}

	@Override
	public boolean asynchronous() {
		return false;
	}

}
